package com.threefish.modules.report.datasource;

import com.alibaba.druid.pool.DruidDataSource;
import com.bstek.ureport.definition.datasource.BuildinDatasource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author 黄川 huchuc@vip.qq.com
 * @date: 2018/9/6
 */
@Service
@Slf4j
public class DefaualtBuildinDatasource implements BuildinDatasource {

    @Autowired
    private DruidDataSource dataSource;

    @Override
    public String name() {
        return dataSource.getName();
    }

    @Override
    public Connection getConnection() {
        try {
            return dataSource.getConnection();
        } catch (SQLException e) {
            log.error("取得内置数据源连接失败", e);
        }
        return null;
    }
}
